import type {
  AccountInfo,
  AccountSettlementRecords,
  ContractInfoDetail,
  FinanceAdvanceApplication,
  FinanceAttachmentPageRequest,
  FinanceAttachmentPageResponse,
  FinanceExpenseReimbursement,
  FinancePaymentApplication,
  InvoicApplyRecord,
  OpenAcceptanceBill,
  OtherReceivedAcceptanceBill,
  ProjectInfoDetail,
  ReceiptRecordRefund,
  ReceiptRecordRelease,
  SettlementActualReceiptPayment,
  SettlementInfo,
  SysReceiptRecordDetails,
  WaybillCarrierOwnerBill,
} from './types/finance'
import { http } from '@/http/http'

/**
 * 获取预支申请详情
 * @param id 申请ID
 * @returns 预支申请详情
 */
export function getFinanceAdvanceApplicationById(id: string) {
  return http.get<FinanceAdvanceApplication>('/yngy-logistics/logistics/financeAdvanceApplication/getFinanceAdvanceApplicationById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取费用报销详情
 * @param id 报销ID
 * @returns 费用报销详情
 */
export function getFinanceExpenseReimbursementById(id: string) {
  return http.get<FinanceExpenseReimbursement>('/yngy-logistics/logistics/financeExpenseReimbursement/getFinanceExpenseReimbursementById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取退款申请详情
 * @param id 申请ID
 * @returns 退款申请详情
 */
export function getFinancePaymentApplicationById(id: string) {
  return http.get<FinancePaymentApplication>('/yngy-logistics/logistics/financePaymentApplication/getFinancePaymentApplicationById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取发票申请详情
 * @param id 申请ID
 * @returns 发票申请详情
 */
export function getInvoicApplyRecordById(id: string) {
  return http.get<InvoicApplyRecord>('/yngy-logistics/logistics/invoicApplyRecord/getInvoicApplyRecordById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取资金退款详情
 * @param id 退款ID
 * @returns 资金退款详情
 */
export function getReceiptRecordRefundById(id: string) {
  return http.get<ReceiptRecordRefund>('/yngy-logistics/logistics/receiptRecordRefund/getReceiptRecordRefundById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取本方支付保证金
 * @param params 查询参数
 * @returns 支付保证金信息
 */
export function getSysSettlementDetails(id: string) {
  return http.get<SettlementInfo>('/yngy-logistics/logistics/settlementInfo/sysSettlementDetails', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取附件列表
 * @param data 请求参数
 * @returns 附件列表
 */
export function getFinanceAttachmentByPage(data: FinanceAttachmentPageRequest) {
  return http.post<FinanceAttachmentPageResponse>('/yngy-logistics/logistics/financeAttachment/getFinanceAttachmentByPage', data)
}

/**
 * 获取付款方式选项
 * @param data 请求参数
 * @returns 付款方式选项
 */
export function listSysFinancePayChannel(data?: Record<string, any>) {
  return http.post<any>('/yngy-logistics/logistics/financePayChannel/listSysFinancePayChannel', data || {})
}

/**
 * 获取收据记录详情
 * @param id 收据记录ID
 * @returns 收据记录详情
 */
export function getSysReceiptRecordDetails(id: string) {
  return http.get<SysReceiptRecordDetails>('/yngy-logistics/logistics/receiptRecord/sysReceiptRecordDetails', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取收据记录释放详情
 * @param id 收据记录释放ID
 * @returns 收据记录释放详情
 */
export function getReceiptRecordReleaseById(id: string) {
  return http.get<ReceiptRecordRelease>('/yngy-logistics/logistics/receiptRecordRelease/getReceiptRecordReleaseById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取外收承兑汇票详情
 * @param id 外收承兑汇票ID
 * @returns 外收承兑汇票详情
 */
export function getOtherReceivedAcceptanceBillById(id: string) {
  return http.get<OtherReceivedAcceptanceBill>('/yngy-logistics/logistics/billOutAcceptance/getBillOutAcceptanceById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取开具承兑汇票详情
 * @param id 开具承兑汇票ID
 * @returns 开具承兑汇票详情
 */
export function getOpenAcceptanceBillById(id: string) {
  return http.get<OpenAcceptanceBill>('/yngy-logistics/logistics/billIssuedAcceptance/getBillIssuedAcceptanceById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取结算实际收付详情
 * @param id 结算实际收付ID
 * @returns 结算实际收付详情
 */
export function getSettlementActualReceiptPaymentById(id: string) {
  return http.get<SettlementActualReceiptPayment>('/yngy-logistics/logistics/settlementActualReceiptPayment/getSettlementActualReceiptPaymentById', {
    id,
    t: Date.now(),
  })
}
// /yngy-logistics/logistics/settlementInfo/sysSettlementDetails?id=1993222268643381249&t=1764056309904
/**
 * 获取合同详情
 * @param id 合同ID
 * @returns 合同详情
 */
export function getContractInfoDetail(id: string) {
  return http.get<ContractInfoDetail>(`/yngy-logistics/logistics/contract/detailsById`, {
    id,
    t: Date.now(),
  })
}

/**
 * 获取项目详情
 * @param id 项目编号（projectNo）
 * @returns 项目详情
 */
export function getProjectInfoDetailById(id: string) {
  return http.get<ProjectInfoDetail>('/yngy-logistics/logistics/projectInfo/details', {
    projectNo: id,
    t: Date.now(),
  })
}

/**
 * 获取项目文件列表
 * @param projectId 项目ID
 * @returns 文件列表
 */
export function getProjectFileList(projectId: string) {
  return http.post<any[]>('/yngy-logistics/logistics/file/list', {
    projectId,
    timestamp: Date.now(),
  })
}

/**
 * 获取运单承运商账单详情
 * @param id 运单承运商账单ID
 * @returns 运单承运商账单详情
 */
export function getWaybillCarrierOwnerBillById(id: string) {
  return http.get<WaybillCarrierOwnerBill>('/yngy-logistics/logistics/waybillCarrierOwnerBill/getWaybillCarrierOwnerBillById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取资金调拨详情
 * @param id 资金调拨ID
 * @returns 资金调拨详情
 */
export function getAccountSettlementRecordsById(id: string) {
  return http.get<AccountSettlementRecords>('/yngy-logistics/logistics/accountSettlementRecords/getAccountSettlementRecordsById', {
    id,
    t: Date.now(),
  })
}

/**
 * 获取账户信息
 * @param id 账户ID
 * @returns 账户信息
 */
export function getAccountById(id: string) {
  return http.get<AccountInfo>('/yngy-logistics/logistics/account/getAccountById', {
    id,
    t: Date.now(),
  })
}

// 导出默认对象，保持向后兼容
export default {
  getFinanceAdvanceApplicationById,
  getFinanceExpenseReimbursementById,
  getSysReceiptRecordDetails,
  getFinancePaymentApplicationById,
  getInvoicApplyRecordById,
  getReceiptRecordRefundById,
  getWaybillCarrierOwnerBillById,
  getReceiptRecordReleaseById,
  getSettlementActualReceiptPaymentById,
  getSysSettlementDetails,
  getFinanceAttachmentByPage,
  listSysFinancePayChannel,
  getOtherReceivedAcceptanceBillById,
  getOpenAcceptanceBillById,
  getContractInfoDetail,
  getProjectInfoDetailById,
  getProjectFileList,
  getAccountSettlementRecordsById,
  getAccountById,
}
